var Tool = require('common/tool');
var Config = require('common/config');
var parameter,
    page;

require('sass/reset.scss');
require('sass/tool.scss');
Tool.avalonForIe7(avalon);

require('../../../directives/count-directive');
require('../../../directives/digits-directive');
require('filters/filter');
require('comp/footerCopyright');
require('./index.scss');

/* 获取url的参数 */
function queryURLParams() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
       var str = url.substr(1);
       var strs = str.split("&");
       for(var i = 0; i < strs.length; i ++) {
          theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
       }
    }
    return theRequest;
}
parameter = queryURLParams();

/* 创建avalon数据模型 */
var vm = avalon.define({
    $id: 'depositResult',
    payment:'',
    pay_respMsg:'',
    result:'',
    close:function(){
        window.close();
    }
});

vm.$watch('onReady',function(v){
    page = new pageModel();
    window['vm'] = vm;
});


function pageModel(){
    this.getInfo();
}

/* 获取存款数据 */
pageModel.prototype.getInfo = function(){
    var that = this;
    Tool.ajax({
        url:'/EgpayResult',
        data:{
            merchantId: parameter.merchantId
        },
        type:"post"
    }).done(function(res){
        var code = res.code;
        if(!res || code!='0'){
            layer.alert(res.msg);
            return false;
        }
        var data = res.data;
        vm.pay_respMsg = data.pay_respMsg;
        vm.payment = data.payment || {};
        vm.result = data.result;
        if( data.result==='success' ){
            vm.payment.status = '已完成';
        }else{
            vm.payment.status = data.pay_respMsg || '支付失败';
        }
    });
}
